    (function($,window){
        window.CommonScript = {};
        /* 
         * 实现功能：页面数据只读或可编辑
         * 调用方法CommonScript.dataDisabledOrEdit($this,flag);
         * 参数$this:表单父级标签id对象
         * 参数flag为false时可编辑，为true时不可编辑
         * 参数$comboboxObj 下拉框对象
         */
        CommonScript.dataDisabled = function($obj,flag,$comboboxObj){
            $obj.find('input,select,textarea').each(function(){
               if(flag){
                    $(this).attr('disabled', true);
                }else{
                    $(this).attr('disabled', false);
                }
            });

            /*if($comboboxObj){
                $comboboxObj.each(function(){
                    $(this).combobox({
                        onLoadSuccess:function(){
                            if(flag){
                                $(this).combobox('disable');
                            }else{
                                $(this).combobox('enable');
                            }
                        }
                    });
                });
            };*/
        };

        /*
         *  调用方法: CommonScript.getFormObjStr($form, exception);
         *  getFormObjStr  getFormObj
         *  获取表单值，并转为字符串
         *  param:  $form       表单的jQuery对象
         *          exception   排除不需要的项
         *  author: zsk 2014-07-31 
         */
        CommonScript.getFormObj = function($form, exception) {
            var param = {};
            $("[name]", $form).each(function() {

                // 如果name为空不执行：修改：yyp 2016-03-25
                if ($(this).attr('name')) {    
                    var $this = $(this);
                    if ($this.attr("type") == "radio") {
                        if ($this.prop("checked")) {
                            param[$this.attr("name")] = $.trim($this.val());
                        }
                    }else if($this.attr("type") == "checkbox"){
                        if ($this.prop("checked")) {
                            param[$this.attr("name")] === undefined ? 
                                param[$this.attr("name")] = $.trim($this.val()) : 
                                param[$this.attr("name")] += (',' + $.trim($this.val()));
                        }
                    } else {
                        param[$this.attr("name")] = $.trim($this.val());
                    }
                }
            });
            if(exception){ // delete exception
                for(var i = 0, j = exception.length; i < j; i++){
                    delete param[exception[i]];
                }
            }
            
            return param;
        };

        CommonScript.getFormObjStr = function($form, exception) {
            var paramObj = this.getFormObj($form, exception);
            return JSON.stringify(paramObj);
        };

        /*
         *  getFormObjStr方法扩展,可获取参数对象下有name属性的表单值,用于必填项校验等
         *  调用方法: CommonScript.getFieldValue(objs);
         *  传后台时需使用JSON.stringify(param)方法转换
         *  getFieldValue
         *  获取表单值，并转为字符串
         *  param:  objs  表单所属父级(id、class名或其他dom元素)--必传参数;
         *          isFlag  是否需要进行非空校验(校验对象为input及textarea)
         *          $comboObj  所需查找的jQuery下拉框对象(适用于easyui单选下拉框)
         *  author: zxy 2016-03-02 
         */
        CommonScript.getFieldValue = function(objs,isFlag,$comboObj) {
            
            var param = {},isValidate = true;
            // 默认 判断校验通过字段为true
            param['validatePass'] = true;

            $(objs).find('[name]').each(function() {
                var $this = $(this);
                if(!isValidate){
                    return;
                };
                if($this.attr("type") == "radio") {
                    if($this.prop("checked")) {
                        param[$this.attr("name")] = $this.val();
                    }
                }else if($this.attr("type") == "checkbox"){
                    if($this.prop("checked")) {
                        param[$this.attr("name")] === undefined ? 
                            param[$this.attr("name")] = $this.val() : 
                            param[$this.attr("name")] += (',' + $this.val());
                    }
                }else{
                    if(isFlag){
                        if($this.is(":hidden") == false && this.name != "" && $.trim($this.val()) == ""){
                            CommonScript.noNullCheck($this);
                            isValidate = false;
                            param['validatePass'] = false;
                            return false;
                        }
                    }
                    param[$this.attr("name")] = $this.val();
                }
            });
        
            if(!param['validatePass']){
                return false;
            }else if($comboObj){
                CommonScript.validateCombo(param,objs,$comboObj,isFlag);
                if(param.flag){
                    delete param['validatePass'];
                    delete param.flag;
                    return param;
                }else{
                    return false;
                }
            }else{
                delete param['validatePass'];
                return param;
            }

        };

        /* 校验下拉框是否必填 
        *  参数: 
        *      formObjs:    CommonScript.getFieldValue方法取值及校验结果
        *      objs:        下拉框所属父级(id、class名或其他dom元素)
        *      $comboObj:   所需查找的jQuery对象
        *      isFlag:      下拉框是否进行非空校验
        *  author: zxy 2016-03-02 
        */
        CommonScript.validateCombo = function(formObjs,objs,$comboObj,isFlag){
            var flag = true,validatePass = true;
            $(objs).find($comboObj).each(function(){
                var $this = $(this),curValue = $this.combobox('getValues');
                if(!flag){
                    return;
                }
                if(isFlag && (curValue[0] == "" || curValue.length == 0)  ){
                    flag = false;
                    CommonScript.noNullCheck($this);
                }
                formObjs[$this.attr("comboname")] = curValue ? curValue.join(",") : "";
                formObjs.flag = flag;
            });
            //return formObjs;
        };

        // 表单非空校验提示
        CommonScript.noNullCheck = function($currentCheck){
            var opts = {
                msg : "请将信息填写完整!", 
                onClose:function(){
                    $currentCheck.focus();
                }
            }
            CommonScript.keyEnterMessager(opts);
        };

        /* easyui下拉框批量设值
        *  参数: 
        *      objs:        下拉框所属父级(id、class名或其他dom元素)
        *      $comboObj:   所需查找的jQuery对象
        *      comboValues: 对应值json对象
        *  author: zxy 2016-03-10
        */
        CommonScript.setComboValues = function(objs,$comboObj,comboValues){
            $(objs).find($comboObj).each(function(){
                var $this = $(this);
                $this.combobox({
                    onLoadSuccess:function(){
                        var fieldValue = $this.attr('comboname');
                        if(comboValues[fieldValue] != 'null' && comboValues[fieldValue] != null && comboValues[fieldValue] != "" ){
                            $this.combobox('setValues',comboValues[fieldValue]);
                        }else{
                            $this.combobox('clear');
                        }
                    }
                });
            });
        };

        /* 省份查询  根据中文输入模糊查询
        *  q: 下拉框输入内容
        *  row: 下拉选项行
        *  obj: 下拉框对象
        *  author: zxy 2016-03-04 
        */
        CommonScript.searchProvince = function(q, row, obj){
            var opts = $(obj).combobox('options');
            return row[opts.textField].indexOf(q) >= 0;
        };

        //从URL中解析参数
        CommonScript.urlArgs = function(){
            var args = {};
            var query = location.search.substring(1);
            var pairs = query.split("&");
            for(var i = 0; i<pairs.length; i++){
                var pos = pairs[i].indexOf('=');
                if(pos == -1) continue;
                var name = pairs[i].substring(0,pos);
                var value = pairs[i].substring(pos +1);
                value = decodeURIComponent(value);
                args[name] = value;
            }
            return args;
        };

        // 电话号码校验--手机号码及座机
        // phoneObj 输入框对象
        // author: wyf 2016-03-02 
        CommonScript.checkPhoneNumber = function(phoneObj){
            var isMobile=/^(?:13\d|15\d|18\d)\d{5}(\d{3}|\*{3})$/;  //手机号码验证规则
            var isPhone=/^(\d{3,4}\-?)?\d{6,8}$/;   //座机验证规则
            if(phoneObj.value && !isMobile.test(phoneObj.value) && !isPhone.test(phoneObj.value)){ // 如果用户输入的值不同时满足手机号和座机号的正则
                var options = {
                    msg : "电话或手机格式错误!", 
                    onClose:function(){
                        $(phoneObj).val('');
                    }
                }
                CommonScript.keyEnterMessager(options);
                return false;
            }
        };

        // 邮箱校验
        // emailObj 输入框对象
        // author: wyf 2016-03-02 
        CommonScript.checkEmail = function(emailObj){
            var isEmail = /^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/;
            if(!isEmail.test(emailObj.value) && emailObj.value){
                var options = {
                    msg : "电子邮件格式错误!", 
                    onClose:function(){
                        $(emailObj).val('');
                    }
                }
                CommonScript.keyEnterMessager(options);
                return false;
            }
        };

        // 传真校验
        // faxObj 输入框对象
        // author: wyf 2016-03-25 
        CommonScript.checkFax = function(faxObj){
            var isFax = /^(\d{3,4}-)?\d{7,8}$/;
            if(!isFax.test(faxObj.value) && faxObj.value){
                var options = {
                    msg : "传真格式错误!", 
                    onClose:function(){
                        $(faxObj).val('');
                    }
                }
                CommonScript.keyEnterMessager(options);
                return false;
            }
        };


        /* 取消浏览器的事件传递
         * author: wyf 2016-03-09 
         */
        CommonScript.stopDefaultPropagation = function(event){
            event = event || window.event;
            if(event.stopPropagation){
                event.stopPropagation();
            }else{
                event.cancelBubble = true;
            }
        }

        /* easyui年月控件扩展
         * $formatterDateId: datebox对象 ,defaultMonth:是true/否false需要设置默认值:默认需要设置
         * author yyp 2016-03-04
         */
        CommonScript.showMonth = function($formatterDateId,defaultMonth) {

            $formatterDateId.datebox({

                onShowPanel: function() {  // 显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
                    span.trigger('click'); // 触发click事件弹出月份层
                    if (!tds) setTimeout(function() { //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
                        tds = p.find('div.calendar-menu-month-inner td');
                        tds.click(function(e) {
                            e.stopPropagation(); // 禁止冒泡执行easyui给月份绑定的事件
                            var year = /\d{4}/.exec(span.html())[0],        // 得到年份
                                month = parseInt($(this).attr('abbr'), 10); // 月份
                            $formatterDateId.datebox('hidePanel')           // 隐藏日期对象
                            .datebox('setValue', year + '-' + month);       // 设置日期的值
                        });

                    }, 0);
                },
                parser: function(s) { // 配置parser，返回选择的日期
                    if (!s) return new Date();
                    var arr = s.split('-');
                    return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
                },
                formatter: function(d) { // 配置formatter，只返回年月
                    if(d.getMonth()<9){
                        return  d.getFullYear() + '-0' + (d.getMonth()+1);
                    }
                    return d.getFullYear() + '-' + (d.getMonth()+1);
                } 
            });

            var p = $formatterDateId.datebox('panel'), // 日期选择对象
                tds = false,                           // 日期选择对象中月份
                span = p.find('.calendar-title>span'); // 显示月份层的触发控件

            // 隐藏日历控件按钮：存在bug,easyui官网本身就有该问题
            $('.calendar-prevmonth, .calendar-nextmonth').hide();

            // $formatterDateId.datebox('setValue','2015-02');
            
            // 默认显示时间:默认为true
            var isSetDefault = defaultMonth == false ? defaultMonth : true;
            if (isSetDefault == true) {
                CommonScript.setDefaultMonth($formatterDateId);
            }
        };

        /*  默认显示时间: 目前为上个月时间
         *  关于年月控件：默认值设置：后期只需修改此方法；
         *  author yyp 2016-03-21
         */
        CommonScript.setDefaultMonth = function($formatterDateId) {
            var current = new Date();
            new Date(current.setMonth((new Date().getMonth()-1)));

            $formatterDateId.datebox('setValue',new Date().getFullYear() +'-'+ (new Date().getMonth()+1));
        };       

        /* 开始时间小于结束时间
         * opts:$beginTime   $endTime 
         * showDay: 是否为datebox:默认为datatimebox
         * author yyp 2016-03-10
         */
        CommonScript.compareTimes = function (opts, showDay) {

            if (showDay == true){

                // 解决new Date()对浏览器兼容问题。
                var beginTimes= opts.$beginTime.datebox('getValue').toString();
                var endTimes= opts.$endTime.datebox('getValue').toString();
                var start =  new Date(Date.parse(beginTimes.replace(/-/g,"/")));
                var end =  new Date(Date.parse(endTimes.replace(/-/g,"/")));
                
                if (end<start) {
                    opts.$beginTime.datebox('setValue','');
                    opts.$endTime.datebox('setValue','');
                    $.messager.alert('提示信息','查询开始时间不能大于查询结束时间','info');
                }
            } else {
                // 解决new Date()对浏览器兼容问题。
                var beginTime= opts.$beginTime.datetimebox('getValue').toString();
                var endTime= opts.$endTime.datetimebox('getValue').toString();
                var sd =  new Date(Date.parse(beginTime.replace(/-/g,"/")));
                var ed =  new Date(Date.parse(endTime.replace(/-/g,"/")));
                
                if (ed<sd) {
                    opts.$beginTime.datetimebox('setValue','');
                    opts.$endTime.datetimebox('setValue','');
                    $.messager.alert('提示信息','查询开始时间不能大于查询结束时间','info');
                }
            }
        };

        /*
         * 消息提示框关闭时执行自定义的方法
         * 在消息提示框打开前移除回车事件，消息关闭时添加回车事件
         * keyEnterIndex 页面层级; opts 提示框参数对象
         * author wyf 2016-03-17
         */
        CommonScript.keyEnterMessager = function(keyEnterIndex, opts){

            //如果只传提示框参数对象不传页面层级参数，则只执行自定义的提示框关闭方法
            if(typeof keyEnterIndex != 'object'){
                CommonScript.keyEnter.off(keyEnterIndex);
            }else{
                opts = keyEnterIndex;
            }
            var options = {
                title : "提示", 
                msg : "请选择一行记录!", 
                icon : "info",
                onBeforeClose:function(){
                    if(typeof keyEnterIndex != 'object'){
                        CommonScript.keyEnter.on(keyEnterIndex);
                    }
                }
            }
            opts = $.extend(options, opts);
            $.messager.alert(options);
        };

        /*
         * 模糊查询限制输入特殊字符例如:"%或_"
         * params $selector 选择器; special保存需限制的特殊字符数组
         * author wyf 2016-03-17
         */
        CommonScript.limitInputSpecial = function($selector,special){
            
            $selector.on('change keyup blur keydown',function(){
                var _self = this;
                $.each(special,function(i,n){
                    if(_self.value.indexOf(n) != -1){
                        _self.value = _self.value.replace(n,'');
                    }
                })
            });
        };

        /* public 限制文本宽长度
         * params: eleId 文本框ID；len 长度
         * author wyf 2016-04-13
         */
        CommonScript.limitInputLength = function(eleId,len){
          $("#"+eleId).on('change keyup blur keydown',function(){
            if(this.value.length>len){
              this.value = this.value.substr(0,len);
            }
          });
        }

        // 将今天之后的日期disable
        CommonScript.disableAfter = function($thisDate) {
            $thisDate.datebox().datebox('calendar').calendar({
                validator: function(date){
                    var now = new Date();
                    var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
                    return d1>=date;
                }
            });
        };

        /*
            author zsk
            回车绑定方法
        */
        CommonScript.keyEnter = {

            // 绑定的回调方法数量
            _bindLength: 0

            , _onBindFuns: []
            , _offBindFuns: []

            , _isExsit: function (tage) {

                var result = false;

                if (typeof _allBindFun !== undefined) {
                    result = true;
                }

                return result;
            }

            // 回车后的调用的方法
            , _fireFun: function (e) {
                if (e.keyCode == 13) {
                    for (var i = this._onBindFuns.length; i >= 0; i--) {
                        if (this._onBindFuns[i] !== undefined) {
                            return this._onBindFuns[i].call(null, e);
                        }
                    }
                    ;
                }

            }

            // 添加回车事件
            , on: function keyEnterOn(zindex, fun) {
                var _self = this;

                if (fun) {
                    this._onBindFuns[zindex] = fun
                    ++this._bindLength;
                } else {
                    if (this._offBindFuns[zindex] != undefined) {
                        this._onBindFuns[zindex] = this._offBindFuns[zindex];
                        this._offBindFuns[zindex] = undefined;
                        ++this._bindLength;
                    }
                }
                if (this._bindLength == 1) {
                    $(document).on('keydown._keyEnter', function (e) {
                        _self._fireFun.call(_self, e);
                    });
                }
            }

            // 移除回车事件
            , off: function keyEnterOff(zindex) {
                if (this._onBindFuns[zindex] != undefined) {
                    --this._bindLength
                    this._offBindFuns[zindex] = this._onBindFuns[zindex];
                    this._onBindFuns[zindex] = undefined;
                }

                if (this._bindLength == 0) {
                    $(document).off('keydown._keyEnter');
                }
            }
        };

        /*  动态创建dialog并打开，在关闭时销毁 
         *  dialogId： 需要创建的dialog的Id
         *  dialogOpts: 传入的dialog对象
         *  callbackOrIndex: 如果是回调方法则直接调用，
         *  如果是字符串则调用默认方法，传入的是需要关闭的keyEnter方法
         *  author yyp 2016-03-25
         */
        CommonScript.buildDialog = function(dialogId, opts, callbackOrIndex){
            var callback;
            if(callbackOrIndex) {
                var isCallBack = $.type(callbackOrIndex);
                if (isCallBack === 'function') {
                    callback = callbackOrIndex;
                } else {
                    callback = function(){
                        CommonScript.keyEnter.off(callbackOrIndex); 
                    };
                }
            } else {
                callback = function () {};
            }

            var defaultDialogOpts = {
                closable: true,
                closed: true,
                modal: true,
                width: 900,
                height: 500,
                shadow:false,
                method: 'post',
                id: dialogId,
                onBeforeClose: callback, 
                onClose: function(){

                    // 关闭时销毁弹框 避免多次创建出现重复id
                    $('#'+dialogId).dialog('destroy');
                }
            };

            var optionDialog = $.extend({}, defaultDialogOpts, opts);
            $('<div></div>').dialog(optionDialog);
            
            $("#"+dialogId).dialog('open');
        };

        /*  创建 datagrid 方法
         *  grid:需要创建的datagrid
         *  opts: datagrid对象
         *  author yyp 2016-03-28
         */
        CommonScript.createGrid = function (grid, opts, params, callbackDblClickRow) {
            var defaultGridOps = {
                pagination: true,
                pageNumber: 1,
                autoRowHeight: false,
                rownumbers: true,
                fitColumns: true,
                nowrap: false,
                singleSelect: true,
                fit: true,
                border: false,
                queryParams: params || null,
                onDblClickRow: callbackDblClickRow || function(){}
            };

            var optionGrid = $.extend({}, defaultGridOps, opts);
            grid.datagrid(optionGrid);
        };

        /*  动态解析内容，只有在打开dialog或页面的时候才开始解析
         *  wrapperId: html代码解析后需要放到的父容器Id
         *  toParserId：待解析的html代码存放位置的Id
         *  callBack: 需要执行的方法
         *  author yyp 2016-03-25
         */
        CommonScript.parserDialog = function(wrapperId, toParserId, callBack) {
            $.parser.onComplete = function (context) {
                if (context == ('#'+wrapperId)) {  // TODO ?
                    callBack && callBack();
                }
            };
            var html = document.getElementById(toParserId).innerHTML;
            document.getElementById(wrapperId).innerHTML = html;
            $.parser.parse('#'+wrapperId);
        };

    })(jQuery,window);

    /*  扩展easyui-textbox 清空按钮 ,适用于textbox,combobox,datebox等继承textbox的组件
     *  使用例子：$('.easyui-textbox').textbox('addClearBtn');
     *  author：yyp 2016-03-16
     */ 
    $.extend($.fn.textbox.methods, {
        addClearBtn: function(jq, callBack){
            return jq.each(function(){
                var t = $(this);
                var opts = t.textbox('options');
                opts.icons = (opts.icons || []).concat();
                opts.icons.unshift({
                    iconCls: "icon-clear",
                    handler: function(e){
                        $(e.data.target).textbox('clear');
                        $(this).css('visibility','hidden');
                        //如果有，清空其他input值
                        callBack && callBack.call(this);
                    }
                });

                t.textbox();
                if (!t.textbox('getText')){
                    t.textbox('getIcon',0).css('visibility','hidden');
                }

                var icon = t.textbox('getIcon',0);
                
                var inputEle = t.textbox('textbox');
                inputEle.parent().on({
                    mouseover:function(){
                        if (inputEle.val()){
                            icon.css('visibility','visible');
                        }
                    },
                    mouseout : function(){
                        icon.css('visibility','hidden');
                    }
                });
            });
        }
    });

    /*  扩展easyui-combobox 光标在combobox框里面,不执行自定义的按Enter键方法
     *  使用例子：$('#search_dealerTwo_province').combobox('keyEnter',function);
     *  author：wyf 2016-04-29
     */ 
    $.extend($.fn.combobox.methods, {
        keyEnter: function(jq, callBack){
            var obj = jq.combobox('textbox');
            obj.on('keydown', function (e) {
               if(e.keyCode == 13){
                    callBack();
               }
            });
        }
    });


